package com.mlog.njyjy.ndop.share.zabbix.request;

import com.google.gson.Gson;
import com.mlog.njyjy.ndop.share.zabbix.request.core.AbstractZabbixRequest;
import com.mlog.njyjy.ndop.share.zabbix.request.core.AbstractZabbixRequestBuilder;
import com.mlog.njyjy.ndop.share.zabbix.response.ZabbixResponse;
import com.mlog.njyjy.ndop.share.zabbix.support.Param;

import java.util.Map;

/**
 * <p>
 * 用户login
 * </p>
 *
 * @author <a href="mailto:yingxiufeng@mlogcn.com">alex</a>
 * @version v1.0, 2020/7/20
 */
public class ZabbixUserLoginRequest extends AbstractZabbixRequest<ZabbixResponse> {

    private boolean userData = false;

    @Param("user")
    private String username;

    private String password;


    private ZabbixUserLoginRequest(Builder builder) {
        this.userData = builder.showUserData;
        this.username = builder.username;
        this.password = builder.password;
    }

    /**
     * method
     * eg 'user.login'
     *
     * @return
     */
    @Override
    public String getMethod() {
        return "user.login";
    }

    /**
     * 请求的参数
     *
     * @return
     */
    @Override
    public Map<String, Object> getParams() {
        return getParamsByDefault();
    }

    @Override
    public ZabbixResponse createNewResponse(String responseBody, int statusCode, String reasonPhrase, Gson gson) {
        return createNewResponse(new ZabbixResponse(gson), responseBody, statusCode, reasonPhrase);
    }

    public static class Builder extends AbstractZabbixRequestBuilder<ZabbixUserLoginRequest, Builder> {

        private boolean showUserData;

        private String username;

        private String password;


        public Builder showUserData(Boolean showUserData) {
            this.showUserData = showUserData;
            return this;
        }

        public Builder username(String username) {
            this.username = username;
            return this;
        }

        public Builder password(String password) {
            this.password = password;
            return this;
        }

        /**
         * build request
         *
         * @return
         */
        @Override
        public ZabbixUserLoginRequest build() {
            return new ZabbixUserLoginRequest(this);
        }
    }
}
